package com.xin.marcus.controller;


import com.xin.marcus.service.DownLoadExcelService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@RestController
@RequestMapping("/xlsx")
public class FileExportController {

    @Resource
    private DownLoadExcelService downLoadExcelService;

    @RequestMapping("/hello")
    public String helloLogin(){
        return "toExcelPage";
    }

    /**
     * 导出excel
     * @author xin.wang
     * @date 2023/10/25  11:17
     */
    @GetMapping("/downLoadExcel")
    public void downLoadExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        downLoadExcelService.downLoadExcel(request,response);
    }

    /**
     * 文件上传
     * @author xin.wang
     * @date 2023/10/26  9:27
     */
    @ResponseBody
    @RequestMapping("/uploadExcel")
    public String uploadExcel(@RequestParam("file") Part part) throws Exception {
        downLoadExcelService.uploadExcel(part);
        return "上传成功";
    }
}
